#include "XBaseProtocol.h"
#include <sstream>

using namespace std;

XBaseProtocolHead::XBaseProtocolHead()
{
	_magic_num = XBaseProtocol::_magic_num;
	_protocol_ver = XBaseProtocol::_protocol_ver;
	_cmd_type = 0;
	_seq_no = 0;
}

string XBaseProtocolHead::to_string()
{
	ostringstream oss;
	oss << "[MAGIC_NUMBER] " << _magic_num << endl;
	oss << "[PROTOCOL_VERSION] " << _protocol_ver << endl;
	oss << "[COMMAND_TYPE] " << _cmd_type << endl;
	oss << "[SEQUENCE_NO] " << _seq_no << endl;

	return oss.str();
}

XStringStream& operator >> (XStringStream& in, XBaseProtocolHead& other)
{
	in >> other.magic_num() >> other.protocol_version() >> other.cmd_type() >> other.sequence_num();

	return in;
}

XStringStream& operator << (XStringStream& out, XBaseProtocolHead& other)
{
	out << other.magic_num() << other.protocol_version() << other.cmd_type() << other.sequence_num();

	return out;
}

